From 211f5a18bcb6affd06245435dce63d921e2e5ae7 Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Sun, 8 Jul 2018 19:21:28 -0600 Subject: [PATCH] use prefix increment on enums in brauniger_iq, garmin_txt, igc. --- brauniger_iq.cc | 14 +++++++++----- garmin_txt.cc | 26 ++++++++++++++++++-------- igc.cc | 22 +++++++++++++--------- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/brauniger_iq.cc b/brauniger_iq.cc index 17d6c570f..606344b1a 100644 --- a/brauniger_iq.cc +++ b/brauniger_iq.cc @@ -47,12 +47,16 @@ typedef enum { num_states } state_t; static state_t state; -#if __cplusplus -inline state_t operator++(state_t& rs, int) +inline state_t& operator++(state_t& s) // prefix { - return rs = (state_t)((int)rs + 1); + return s = static_cast(s + 1); +} +inline const state_t operator++(state_t& s, int) // postfix +{ + state_t ret(s); + s = ++s; + return ret; } -#endif static const int reqd_bytes[num_states] = { 6, 1, 2, 2, 25, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1 }; @@ -221,7 +225,7 @@ static int process_data(const unsigned char* data) default: fatal(MYNAME ": Bad internal state\n"); } - state++; + ++state; return remaining; } diff --git a/garmin_txt.cc b/garmin_txt.cc index 7b032e629..e084eb2b4 100644 --- a/garmin_txt.cc +++ b/garmin_txt.cc @@ -75,17 +75,27 @@ typedef enum { unknown_header } header_type; -#if __cplusplus -inline header_type operator++(header_type& rs, int) +inline header_type& operator++(header_type& s) // prefix { - return rs = (header_type)((int)rs + 1); + return s = static_cast(s + 1); +} +inline const header_type operator++(header_type& s, int) // postfix +{ + header_type ret(s); + s = ++s; + return ret; } -inline gt_display_modes_e operator++(gt_display_modes_e& rs, int) +inline gt_display_modes_e& operator++(gt_display_modes_e& s) // prefix { - return rs = (gt_display_modes_e)((int)rs + 1); + return s = static_cast(s + 1); +} +inline const gt_display_modes_e operator++(gt_display_modes_e& s, int) // postfix +{ + gt_display_modes_e ret(s); + s = ++s; + return ret; } -#endif #define MAX_HEADER_FIELDS 36 @@ -1002,7 +1012,7 @@ parse_display(const char* str, int* val) return 0; } - for (gt_display_modes_e i = GT_DISPLAY_MODE_MIN; i <= GT_DISPLAY_MODE_MAX; i++) { + for (gt_display_modes_e i = GT_DISPLAY_MODE_MIN; i <= GT_DISPLAY_MODE_MAX; ++i) { if (case_ignore_strcmp(str, gt_display_mode_names[i]) == 0) { *val = i; return 1; @@ -1348,7 +1358,7 @@ garmin_txt_rd_init(const QString& fname) static void garmin_txt_rd_deinit() { - for (header_type h = waypt_header; h <= unknown_header; h++) { + for (header_type h = waypt_header; h <= unknown_header; ++h) { free_header(h); } gbfclose(fin); diff --git a/igc.cc b/igc.cc index b0e3df738..8ee7b4262 100644 --- a/igc.cc +++ b/igc.cc @@ -137,12 +137,16 @@ static void rd_deinit() } typedef enum { id, takeoff, start, turnpoint, finish, landing } state_t; -#if __cplusplus -inline state_t operator++(state_t& rs, int) +inline state_t& operator++(state_t& s) // prefix { - return rs = (state_t)((int)rs + 1); + return s = static_cast(s + 1); +} +inline const state_t operator++(state_t& s, int) // postfix +{ + state_t ret(s); + s = ++s; + return ret; } -#endif /** * Handle pre- or post-flight task declarations. @@ -189,7 +193,7 @@ static void igc_task_rec(const char* rec) rte_head->rte_name = task_num; rte_head->rte_desc = QStringLiteral(DATEMAGIC) + flight_date + QStringLiteral(": ") + task_desc; route_add_head(rte_head); - state++; + ++state; return; } // Get the waypoint @@ -214,25 +218,25 @@ static void igc_task_rec(const char* rec) switch (state) { case takeoff: snprintf(short_name, 8, "TAKEOFF"); - state++; + ++state; break; case start: snprintf(short_name, 8, "START"); tp_ct = 0; - state++; + ++state; break; case turnpoint: if (++tp_ct == num_tp) { - state++; + ++state; } snprintf(short_name, 8, "TURN%02u", tp_ct); break; case finish: snprintf(short_name, 8, "FINISH"); - state++; + ++state; break; case landing: -- 2.30.2